package ProjectPanel;
 
import java.awt.BorderLayout;
 
import java.awt.GridBagConstraints;
 
import java.awt.GridBagLayout;
 
import java.awt.Insets;
 

 


import javax.swing.JButton;
 
import javax.swing.JLabel;
 
import javax.swing.JOptionPane;
import javax.swing.JPanel;
 
import javax.swing.JTextField;
 


import java.awt.GridLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class SubjectRegistPanel extends JPanel{
        private JTextField subnotf;
        private JTextField subtypetf;
        private JTextField subinfotf;
        private JTextField subpointtf;
        private JTextField subnametf;
        private JTextField profnotf;
        private static Connection conn;
    	private static PreparedStatement pstmt;
    	private static ResultSet rs;
    	
        public SubjectRegistPanel() {
                   setLayout( new BorderLayout( 0, 0 ));
 
                //         * TOP *
 
                makeTopPanel();
 
                //        * CENTER *
 
                makeCenterPanel();

                //      * BOTTOM *
 
                makeBottomPanel();
     }
 
        public void makeTopPanel(){
 
                JPanel top = new JPanel();
                add(top, BorderLayout.NORTH);
                
                JLabel nlb1 = new JLabel("과목 정보를 등록해 주세요"); 
                top.add(nlb1);
 
        }
         
        public void makeCenterPanel(){
        	
                JPanel middle = new JPanel(); 
                add(middle, BorderLayout.CENTER); 
                middle.setLayout(new GridLayout(6, 2, 0, 0));
                  
                JLabel subno = new JLabel("과목 번호 :"); 
                middle.add(subno);
                  
                subnotf = new JTextField();
                middle.add(subnotf); 
                subnotf.setColumns(10);
                
                JLabel subname = new JLabel("과목 명 :"); 
                middle.add(subname);
                
                subnametf = new JTextField(); 
                middle.add(subnametf); 
                subnametf.setColumns(10);
               
                JLabel subtype = new JLabel("과목 유형 번호 :"); 
                middle.add(subtype);
                 
                subtypetf = new JTextField(); 
                middle.add(subtypetf); 
                subtypetf.setColumns(10);
                 
                JLabel subinfo = new JLabel("과목 개요 :"); 
                middle.add(subinfo);
                 
                subinfotf = new JTextField(); 
                middle.add(subinfotf); 
                subinfotf.setColumns(10);
                  
                JLabel subpoint = new JLabel("배정 학점 :"); 
                middle.add(subpoint);
                
                subpointtf = new JTextField(); 
                middle.add(subpointtf); 
                subpointtf.setColumns(10);
                
                JLabel profno = new JLabel("교수 번호 :");
                middle.add(profno);
                
                profnotf = new JTextField();
                middle.add(profnotf);
                profnotf.setColumns(10);
                  
        }
 

 
        public void makeBottomPanel(){
 
                JPanel bottom = new JPanel(); 
                add(bottom, BorderLayout.SOUTH);
                  
                JButton btn1 = new JButton("등록"); 
                btn1.addActionListener(new ActionListener() {
                	public void actionPerformed(ActionEvent e) {
                	ReSubjectVO sv = new ReSubjectVO();
                	sv.setSub_no(subnotf.getText());
                	sv.setSub_name(subnametf.getText());
                	sv.setSub_type_no(subtypetf.getText());
                	sv.setSub_info(subinfotf.getText());
                	sv.setSub_point(subpointtf.getText());
                	sv.setProf_no(profnotf.getText());
                	
                	try{
                		
                	conn = ReJDBC_ConnClose.openDataBase();
                	pstmt = conn.prepareStatement(ReJDBC_SQL.SubjectInsertSQL);
                	pstmt.setString(1, sv.getSub_no());
                	pstmt.setString(2, sv.getSub_name());
                	pstmt.setString(3, sv.getSub_type_no());
                	pstmt.setString(4, sv.getSub_info());
                	pstmt.setString(5, sv.getSub_point());
                	pstmt.setString(6, sv.getProf_no());
                	pstmt.executeUpdate();
                	JOptionPane.showMessageDialog(null, "정상적으로 등록되었습니다.");
                	}catch(Exception ex){
                		ex.printStackTrace();
                	}finally{
                		ReJDBC_ConnClose.closeDataBase(conn, pstmt, rs);
                	}
                	
                		
                	
                		
                	}
                });
                bottom.add(btn1);                  
        }
 
} 
